#-*- coding: utf-8 -*-
from Tkinter import *
from tkFileDialog import *
import fileinput
import tkMessageBox
from sys import *
from time import *
import os.path
import profit

root = Tk()


GainMainWithNVar = IntVar()
GainPropWithNVar = IntVar()
GainOthVar = IntVar()

NDSMainVar = IntVar()
GainMainWONVar = IntVar()
NDSPropVar = IntVar()
GainPropWONVar = IntVar()
OtherChargeVar = IntVar()

CurrChargeVar = IntVar()
ProfMainVar = IntVar()
ResPrCostVar = IntVar()
ProfPropVar = IntVar()
OtherProfVar = IntVar()

ProfBefTVar = IntVar()

ProfTaxVar = IntVar()
PureProfVar = IntVar()

"""ma_revenue_with_vat = profit.profits.ma.revenue_with_vat
ma_expenses = profit.profits.ma.expenses
ma_revenue_vat = profit.profits.ma.revenue_vat
ma_revenue_without_vat = profit.profits.ma.revenue_without_vat
ma_profit = profit.profits.ma.profit
sop_revenue_with_vat = profit.profits.sop.revenue_with_vat
sop_residual_value = profit.profits.sop.residual_value
sop_revenue_vat = profit.profits.sop.revenue_vat
sop_revenue_without_vat = profit.profits.sop.revenue_without_vat
sop_profit = profit.profits.sop.profit
oa_revenue = profit.profits.oa.revenue
oa_expenses = profit.profits.oa.expenses
oa_profit = profit.profits.oa.profit
profit_pretax = profit.profits.profit_pretax
profit_clear = profit.profits.profit_clear
profits_tax =profit.profits.profits_tax


GainMainWithNVar.set(ma_revenue_with_vat)
GainPropWithNVar.set(sop_revenue_with_vat)
GainOthVar.set(oa_revenue)
NDSMainVar.set(ma_revenue_vat)
GainMainWONVar.set(ma_revenue_without_vat)
NDSPropVar.set(sop_revenue_vat)
GainPropWONVar.set(sop_revenue_without_vat)
OtherChargeVar.set(oa_expenses)
CurrChargeVar.set(ma_expenses)
ProfMainVar.set(ma_profit)
ResPrCostVar.set(sop_residual_value)
ProfPropVar.set(sop_profit)
OtherProfVar.set(oa_profit)
ProfBefTVar.set(profit_pretax)
ProfTaxVar.set(profits_tax)
PureProfVar.set(profit_clear)"""


def Main_prof(event):
    def calc():
        profit.profits.clear_ma()
        profit.profits.ma.add_revenue_with_vat(int(SummEnt.get()))
        ma_revenue_without_vat = profit.profits.ma.revenue_without_vat
        GainMainWONVar.set(ma_revenue_without_vat)
        ma_revenue_vat = profit.profits.ma.revenue_vat
        NDSMainVar.set(ma_revenue_vat)
        ma_profit = profit.profits.ma.profit
        ProfMainVar.set(ma_profit)
        profit_pretax = profit.profits.profit_pretax
        ProfBefTVar.set(profit_pretax)
        profits_tax =profit.profits.profits_tax
        ProfTaxVar.set(profits_tax)
        profit_clear = profit.profits.profit_clear
        PureProfVar.set(profit_clear)
        Mapr.destroy()

    def Specify():
        Mapr.destroy()

        def gett():
            NameEnt.delete("0",END)
            NameEnt.insert(END,profit.pas.pos[0].name)
            ProfWNDSEnt.delete("0",END)
            ProfWNDSEnt.insert(END,profit.pas.pos[0].revenue_with_vat)
            ProfWONDSEnt.delete("0",END)
            ProfWONDSEnt.insert(END,profit.pas.pos[0].revenue_without_vat)
            PriceWNDSEnt.delete("0",END)
            PriceWNDSEnt.insert(END,profit.pas.pos[0].price_with_vat)
            PriceWONDSEnt.delete("0",END)
            PriceWONDSEnt.insert(END,profit.pas.pos[0].price_without_vat)
            QuantityEnt.delete("0",END)
            QuantityEnt.insert(END,profit.pas.pos[0].volume)
            ChargeEnt.delete("0",END)
            ChargeEnt.insert(END,profit.pas.pos[0].expense)
            TotGainEnt.delete("0",END)
            TotGainEnt.insert(END,profit.pas.pos[0].cost)
            RentEnt.delete("0",END)
            RentEnt.insert(END,profit.pas.pos[0].profitability)

            

        def AddNew():
            if NameEnt.get().strip() and ProfWNDSEnt.get().strip() and ChargeEnt.get().strip() !=None:
                profit.profits.clear_ma()
                profit.pas.pos.append(profit.pas.ProductOrService())
                profit.pas.pos[0].add_name(NameEnt.get())
                profit.pas.pos[0].add_revenue_with_vat(int(ProfWNDSEnt.get()))
                profit.profits.ma.add_revenue_with_vat(int(ProfWNDSEnt.get()))
                GainMainWithNVar.set(int(ProfWNDSEnt.get()))
                profit.pas.pos[0].add_expense(int(ChargeEnt.get()))
                profit.profits.ma.add_expense(int(ChargeEnt.get()))
                CurrChargeVar.set(int(ChargeEnt.get()))
                if ProfWONDSEnt.get().strip()!="":
                    profit.pas.pos[0].add_revenue_without_vat(int(ProfWONDSEnt.get()))
                if QuantityEnt.get().strip()!="":
                    profit.pas.pos[0].add_volume(int(QuantityEnt.get()))
                if PriceWNDSEnt.get().strip()!="":
                    profit.pas.pos[0].add_price_with_vat(int(PriceWNDSEnt.get()))
                if PriceWONDSEnt.get().strip()!="":
                    profit.pas.pos[0].add_price_without_vat(int(PriceWONDSEnt.get()))
                if TotGainEnt.get().strip()!="":
                    profit.pas.pos[0].add_cost(int(TotGainEnt.get()))
                if RentEnt.get().strip()!="":
                    profit.pas.pos[0].add_profitability(int(RentEnt.get()))
                ma_revenue_without_vat = profit.profits.ma.revenue_without_vat
                GainMainWONVar.set(ma_revenue_without_vat)
                ma_revenue_vat = profit.profits.ma.revenue_vat
                NDSMainVar.set(ma_revenue_vat)
                ma_profit = profit.profits.ma.profit
                ProfMainVar.set(ma_profit)
                profit_pretax = profit.profits.profit_pretax
                ProfBefTVar.set(profit_pretax)
                profits_tax =profit.profits.profits_tax
                ProfTaxVar.set(profits_tax)
                profit_clear = profit.profits.profit_clear
                PureProfVar.set(profit_clear)
            else:
                print "ololo"

        Speci = Toplevel(root,bd=2)
        Speci.title("Specify products")
        Speci.transient(root)
        X_co1 = IntVar()
        Y_co1 = IntVar()
        X_co1.set((int(root.winfo_screenwidth())-320)/2)
        Y_co1.set((int(root.winfo_screenheight())-350)/2)
        Speci.geometry("340x340"+"+"+str(X_co1.get())+"+"+str(Y_co1.get()))
        Speci.resizable(width=0,height=0)

        Comm = Label(Speci,text="Введите данные:",justify=LEFT,font=("times",10))
        Name = Label(Speci,text="Название*:",justify=LEFT,font=("times",10))
        ProfWNDS = Label(Speci,text="Выручка c НДС*:",justify=LEFT,font=("times",10))
        ProfWONDS = Label(Speci,text="Выручка без НДС:",justify=LEFT,font=("times",10))
        PriceWNDS = Label(Speci,text="Цена с ндс:",justify=LEFT,font=("times",10))
        PriceWONDS = Label(Speci,text="Цена без ндс:",justify=LEFT,font=("times",10))
        Quantity = Label(Speci,text="Объем:",justify=LEFT,font=("times",10))
        Charge = Label(Speci,text="Затраты*:",justify=LEFT,font=("times",10))
        TotGain = Label(Speci,text="Себестоимость:",justify=LEFT,font=("times",10))
        Rent = Label(Speci,text="Рентабельность:",justify=LEFT,font=("times",10))

        NameEnt = Entry(Speci,width=12,font=("times",10))
        ProfWNDSEnt = Entry(Speci,width=12,font=("times",10))
        ProfWONDSEnt = Entry(Speci,width=12,font=("times",10))
        PriceWNDSEnt = Entry(Speci,width=12,font=("times",10))
        PriceWONDSEnt = Entry(Speci,width=12,font=("times",10))
        QuantityEnt = Entry(Speci,width=12,font=("times",10))
        ChargeEnt = Entry(Speci,width=12,font=("times",10))
        TotGainEnt = Entry(Speci,width=12,font=("times",10))
        RentEnt = Entry(Speci,width=12,font=("times",10))

        Products = Listbox(Speci,selectmode=SINGLE,height=10,width=16,font=("times",10))
        AddPro = Button(Speci,text="Добавить",command=gett,font=("times",10))
        OK = Button(Speci,text="   OK   ",command=AddNew,font=("times",10))

        Comm.place(relx=0.5,rely=0.05,anchor=N)       
        Name.place(relx=0.05,rely=0.17,anchor=W)
        ProfWNDS.place(relx=0.05,rely=0.25,anchor=W)
        ProfWONDS.place(relx=0.05,rely=0.33,anchor=W)
        PriceWNDS.place(relx=0.05,rely=0.41,anchor=W)
        PriceWONDS.place(relx=0.05,rely=0.49,anchor=W)
        Quantity.place(relx=0.05,rely=0.57,anchor=W)
        Charge.place(relx=0.05,rely=0.65,anchor=W)
        TotGain.place(relx=0.05,rely=0.73,anchor=W)
        Rent.place(relx=0.05,rely=0.81,anchor=W)
  
        NameEnt.place(relx=0.4,rely=0.17,anchor=W)
        ProfWNDSEnt.place(relx=0.4,rely=0.25,anchor=W)
        ProfWONDSEnt.place(relx=0.4,rely=0.33,anchor=W)
        PriceWNDSEnt.place(relx=0.4,rely=0.41,anchor=W)
        PriceWONDSEnt.place(relx=0.4,rely=0.49,anchor=W)
        QuantityEnt.place(relx=0.4,rely=0.57,anchor=W)
        ChargeEnt.place(relx=0.4,rely=0.65,anchor=W)
        TotGainEnt.place(relx=0.4,rely=0.73,anchor=W)
        RentEnt.place(relx=0.4,rely=0.81,anchor=W)

        Products.place(relx=0.84,rely=0.14,anchor=N)
        AddPro.place(relx=0.83,rely=0.67,anchor=N)
        OK.place(relx=0.5,rely=0.9,anchor=N)
        
    Mapr = Toplevel(root,bd=2)
    Mapr.title("Primary")
    Mapr.transient(root)
    X_co1 = IntVar()
    Y_co1 = IntVar()
    X_co1.set((int(root.winfo_screenwidth())-230)/2)
    Y_co1.set((int(root.winfo_screenheight())-140)/2)
    Mapr.geometry("230x140"+"+"+str(X_co1.get())+"+"+str(Y_co1.get()))

    MaprLab = Label(Mapr,text="Выручка основной деятельности\nc НДС",justify=CENTER,font=("times",10))
    SummLab = Label(Mapr,text="Сумма:",font=("times",10))
    SummEnt = Entry(Mapr,width=11,textvariable=GainMainWithNVar,font=("times",10))
    Add = Button(Mapr,text="Рассчитать",command=calc,font=("times",10))
    Spec = Button(Mapr,text="Уточнить",command=Specify,font=("times",10))
    Spec.place(relx=0.7,rely=0.75,anchor=N)
    Add.place(relx=0.3,rely=0.75,anchor=N)
    SummEnt.place(relx=0.5,rely=0.5,anchor=N)
    SummLab.place(relx=0.2,rely=0.5,anchor=N)
    MaprLab.place(relx=0.5,rely=0.07,anchor=N)
    Mapr.resizable(width=0,height=0)
    
def Prop_prof(event):

    def calcPro():
        profit.profits.clear_sop()
        profit.profits.sop.add_revenue_with_vat(int(PropSummEnt.get()))
        sop_revenue_without_vat = profit.profits.sop.revenue_without_vat
        GainPropWONVar.set(sop_revenue_without_vat)
        sop_revenue_vat = profit.profits.sop.revenue_vat
        NDSPropVar.set(sop_revenue_vat)
        sop_profit = profit.profits.sop.profit
        ProfPropVar.set(sop_profit)
        profit_pretax = profit.profits.profit_pretax
        ProfBefTVar.set(profit_pretax)
        profits_tax =profit.profits.profits_tax
        ProfTaxVar.set(profits_tax)
        profit_clear = profit.profits.profit_clear
        PureProfVar.set(profit_clear)
        PropPro.destroy()

    def Spec1():

        def AddNew():
            SpecPro.destroy()

        SpecPro = Toplevel(root,bd=2)
        SpecPro.title("Specify property")
        SpecPro.transient(root)
        X_co1 = IntVar()
        Y_co1 = IntVar()
        X_co1.set((int(root.winfo_screenwidth())-320)/2)
        Y_co1.set((int(root.winfo_screenheight())-350)/2)
        SpecPro.geometry("360x340"+"+"+str(X_co1.get())+"+"+str(Y_co1.get()))
        SpecPro.resizable(width=0,height=0)

        CommProLab = Label(SpecPro,text="Введите данные:",justify=LEFT,font=("times",10))
        NameProLab = Label(SpecPro,text="Название:",justify=LEFT,font=("times",10))
        PriceProLab = Label(SpecPro,text="Цена:",justify=LEFT,font=("times",10))
        AmNoProLab = Label(SpecPro,text="Норма амортизации:",justify=LEFT,font=("times",10))
        AmYeProLab = Label(SpecPro,text="Амортизация за год:",justify=LEFT,font=("times",10))
        AmAlProLab = Label(SpecPro,text="Aмортизация:",font=("times",10))
        UseProLab = Label(SpecPro,text="Срок эксплуатации:",font=("times",10))
        ResProLab = Label(SpecPro,text="Остаточная стоимость:",font=("times",10))
        ReveProLab = Label(SpecPro,text="Выручка:",font=("times",10))
        GainProLab = Label(SpecPro,text="Прибыль(%)",font=("times",10))

        NameProEnt = Entry(SpecPro,width=12,font=("times",10))
        PriceProEnt = Entry(SpecPro,width=12,font=("times",10))
        AmNoProEnt = Entry(SpecPro,width=12,font=("times",10))
        AmYeProEnt = Entry(SpecPro,width=12,font=("times",10))
        AmAlProEnt = Entry(SpecPro,width=12,font=("times",10))
        UseProEnt = Entry(SpecPro,width=12,font=("times",10))
        ResProEnt = Entry(SpecPro,width=12,font=("times",10))
        ReveProEnt = Entry(SpecPro,width=12,font=("times",10))
        GainProEnt = Entry(SpecPro,width=12,font=("times",10))

        Props = Listbox(SpecPro,selectmode=SINGLE,height=10,width=16,font=("times",10))
        AddProp = Button(SpecPro,text="Добавить",command=AddNew,font=("times",10))
        OKpro = Button(SpecPro,text="   OK   ",command=AddNew,font=("times",10))

        CommProLab.place(relx=0.5,rely=0.05,anchor=N)       
        NameProLab.place(relx=0.05,rely=0.17,anchor=W)
        PriceProLab.place(relx=0.05,rely=0.25,anchor=W)
        AmNoProLab.place(relx=0.05,rely=0.33,anchor=W)
        AmYeProLab.place(relx=0.05,rely=0.41,anchor=W)
        AmAlProLab.place(relx=0.05,rely=0.49,anchor=W)
        UseProLab.place(relx=0.05,rely=0.57,anchor=W)
        ResProLab.place(relx=0.05,rely=0.65,anchor=W)
        ReveProLab.place(relx=0.05,rely=0.73,anchor=W)
        GainProLab.place(relx=0.05,rely=0.81,anchor=W)
  
        NameProEnt.place(relx=0.45,rely=0.17,anchor=W)
        PriceProEnt.place(relx=0.45,rely=0.25,anchor=W)
        AmNoProEnt.place(relx=0.45,rely=0.33,anchor=W)
        AmYeProEnt.place(relx=0.45,rely=0.41,anchor=W)
        AmAlProEnt.place(relx=0.45,rely=0.49,anchor=W)
        UseProEnt.place(relx=0.45,rely=0.57,anchor=W)
        ResProEnt.place(relx=0.45,rely=0.65,anchor=W)
        ReveProEnt.place(relx=0.45,rely=0.73,anchor=W)
        GainProEnt.place(relx=0.45,rely=0.81,anchor=W)

        Props.place(relx=0.84,rely=0.14,anchor=N)
        AddProp.place(relx=0.83,rely=0.67,anchor=N)
        OKpro.place(relx=0.5,rely=0.9,anchor=N)

    PropPro = Toplevel(root,bd=2)
    PropPro.title("Property")
    PropPro.transient(root)
    X_co1 = IntVar()
    Y_co1 = IntVar()
    X_co1.set((int(root.winfo_screenwidth())-230)/2)
    Y_co1.set((int(root.winfo_screenheight())-140)/2)
    PropPro.geometry("230x140"+"+"+str(X_co1.get())+"+"+str(Y_co1.get()))
    PropPro.resizable(width=0,height=0)

    PropLab = Label(PropPro,text="Выручка от продажи имущества\nc НДС",justify=CENTER,font=("times",10))
    PropSummLab = Label(PropPro,text="Сумма:",font=("times",10))
    PropSummEnt = Entry(PropPro,width=11,textvariable=GainPropWithNVar,font=("times",10))
    PropAdd = Button(PropPro,text="Рассчитать",command=calcPro,font=("times",10))
    PropSpec = Button(PropPro,text="Уточнить",command=Spec1,font=("times",10))

    PropSpec.place(relx=0.7,rely=0.75,anchor=N)
    PropAdd.place(relx=0.3,rely=0.75,anchor=N)
    PropSummEnt.place(relx=0.5,rely=0.5,anchor=N)
    PropSummLab.place(relx=0.2,rely=0.5,anchor=N)
    PropLab.place(relx=0.5,rely=0.07,anchor=N)
    PropPro.resizable(width=0,height=0)

def OthAct(event):
    
    def calcOtA():
        profit.profits.clear_oa()
        profit.profits.oa.add_revenue(int(OtASummEnt.get()))
        oa_profit = profit.profits.oa.profit
        OtherProfVar.set(oa_profit)
        profit_pretax = profit.profits.profit_pretax
        ProfBefTVar.set(profit_pretax)
        profits_tax =profit.profits.profits_tax
        ProfTaxVar.set(profits_tax)
        profit_clear = profit.profits.profit_clear
        PureProfVar.set(profit_clear)
        OtA.destroy()

    def SpecOtA():
        
        def AddNew():
            SpecOtA.destroy()

    OtA = Toplevel(root,bd=2)
    OtA.title("Прочие доходы")
    OtA.transient(root)
    X_co1 = IntVar()
    Y_co1 = IntVar()
    X_co1.set((int(root.winfo_screenwidth())-230)/2)
    Y_co1.set((int(root.winfo_screenheight())-140)/2)
    OtA.geometry("230x140"+"+"+str(X_co1.get())+"+"+str(Y_co1.get()))
    OtA.resizable(width=0,height=0)

    OtALab= Label(OtA,text="Прочие доходы:",justify=CENTER,font=("times",10))
    OtASummLab = Label(OtA,text="Сумма:",font=("times",10))
    OtASummEnt = Entry(OtA,width=11,textvariable=GainOthVar,font=("times",10))
    OtAAdd = Button(OtA,text="Рассчитать",command=calcOtA,font=("times",10))
    OtASpec = Button(OtA,text="Уточнить",command=SpecOtA,font=("times",10))

    OtASpec.place(relx=0.7,rely=0.75,anchor=N)
    OtAAdd.place(relx=0.3,rely=0.75,anchor=N)
    OtASummEnt.place(relx=0.5,rely=0.5,anchor=N)
    OtASummLab.place(relx=0.2,rely=0.5,anchor=N)
    OtALab.place(relx=0.5,rely=0.07,anchor=N)
    OtA.resizable(width=0,height=0)
  
def Charge(event):

    def Show_charges(event):

        if Types.get(ACTIVE)== u'Оплата труда':
            frame1 = Frame(Ch,width=225,height=250)

            WageLab = Label(frame1,text="Зарплата:",font=("times",10))
            NumberLab = Label(frame1,text="Число рабочих:",font=("times",10))
            BonusLab = Label(frame1,text="Бонус:",font=("times",10))
            DistrLab = Label(frame1,text="Районный коэфф:",font=("times",10))
            SctaxLab = Label(frame1,text="Страховые взносы:",font=("times",10))
            TaxLab = Label(frame1,text="Налоги:",font=("times",10))

            WageEnt = Entry(frame1,width=12,font=("times",10))
            NumberEnt = Entry(frame1,width=12,font=("times",10))
            BonusEnt = Entry(frame1,width=12,font=("times",10))
            DistrEnt = Entry(frame1,width=12,font=("times",10))
            SctaxEnt = Entry(frame1,width=12,font=("times",10))
            TaxEnt = Entry(frame1,width=12,font=("times",10))

            WageLab.place(relx=0.05,rely=0.08,anchor=W)
            NumberLab.place(relx=0.05,rely=0.17,anchor=W)
            BonusLab.place(relx=0.05,rely=0.25,anchor=W)
            DistrLab.place(relx=0.05,rely=0.33,anchor=W)
            SctaxLab.place(relx=0.05,rely=0.41,anchor=W)
            TaxLab.place(relx=0.05,rely=0.49,anchor=W)

            WageEnt.place(relx=0.6,rely=0.08,anchor=W)
            NumberEnt.place(relx=0.6,rely=0.17,anchor=W)
            BonusEnt.place(relx=0.6,rely=0.25,anchor=W)
            DistrEnt.place(relx=0.6,rely=0.33,anchor=W)
            SctaxEnt.place(relx=0.6,rely=0.41,anchor=W)
            TaxEnt.place(relx=0.6,rely=0.49,anchor=W)

            frame1.place(relx=0.03,rely=0.519,anchor=W)

        if Types.get(ACTIVE)== u'Амортизация':
            frame1 = Frame(Ch,width=225,height=250)

            FundsLab = Label(frame1,text="Фонды:",font=("times",10))
            NormLab = Label(frame1,text="Норма амортизации:",font=("times",10))

            FundsEnt = Entry(frame1,width=12,font=("times",10))
            NormEnt = Entry(frame1,width=12,font=("times",10))

            FundsLab.place(relx=0.05,rely=0.08,anchor=W)
            NormLab.place(relx=0.05,rely=0.17,anchor=W)

            FundsEnt.place(relx=0.64,rely=0.08,anchor=W)
            NormEnt.place(relx=0.64,rely=0.17,anchor=W)

            frame1.place(relx=0.03,rely=0.519,anchor=W)

        if Types.get(ACTIVE)== u'Электроэнергия':
            frame1 = Frame(Ch,width=225,height=250)

            UseLab = Label(frame1,text="Расход э.энергии:",font=("times",10))
            RateLab = Label(frame1,text="Тариф:",font=("times",10))

            UseEnt = Entry(frame1,width=12,font=("times",10))
            RateEnt = Entry(frame1,width=12,font=("times",10))

            UseLab.place(relx=0.05,rely=0.08,anchor=W)
            RateLab.place(relx=0.05,rely=0.17,anchor=W)

            UseEnt.place(relx=0.6,rely=0.08,anchor=W)
            RateEnt.place(relx=0.6,rely=0.17,anchor=W)

            frame1.place(relx=0.03,rely=0.519,anchor=W)
            
        if Types.get(ACTIVE)== u'Аренда':
            frame1 = Frame(Ch,width=225,height=250)

            SizeLab = Label(frame1,text="Арендуемая площадь:",font=("times",10))
            RateSLab = Label(frame1,text="Тариф:",font=("times",10))

            SizeEnt = Entry(frame1,width=12,font=("times",10))
            RateSEnt = Entry(frame1,width=12,font=("times",10))

            SizeLab.place(relx=0.05,rely=0.08,anchor=W)
            RateSLab.place(relx=0.05,rely=0.17,anchor=W)

            SizeEnt.place(relx=0.63,rely=0.08,anchor=W)
            RateSEnt.place(relx=0.63,rely=0.17,anchor=W)

            frame1.place(relx=0.03,rely=0.519,anchor=W)

        if Types.get(ACTIVE)== u'Налог на имущество':
            frame1 = Frame(Ch,width=225,height=250)

            ExpLab = Label(frame1,text="Стоимость имущества:",font=("times",10))
            VolLab = Label(frame1,text="Налог(глоб.):",font=("times",10))

            ExpEnt = Entry(frame1,width=12,font=("times",10))
            VolEnt = Entry(frame1,width=12,font=("times",10))

            ExpLab.place(relx=0.05,rely=0.08,anchor=W)
            VolLab.place(relx=0.05,rely=0.17,anchor=W)

            ExpEnt.place(relx=0.67,rely=0.08,anchor=W)
            VolEnt.place(relx=0.67,rely=0.17,anchor=W)

            frame1.place(relx=0.03,rely=0.519,anchor=W)
            
        if Types.get(ACTIVE)== u'Прочие расходы':
            frame1 = Frame(Ch,width=225,height=250)

            OthSumLab = Label(frame1,text="Сумма:",font=("times",10))

            OthSumEnt = Entry(frame1,width=12,font=("times",10))
            
            OthSumLab.place(relx=0.05,rely=0.08,anchor=W)

            OthSumEnt.place(relx=0.67,rely=0.08,anchor=W)

            frame1.place(relx=0.03,rely=0.519,anchor=W)

        if Types.get(ACTIVE)== u'Сырье и материалы':
            frame1 = Frame(Ch,width=225,height=250)

            MatLab = Label(frame1,text="Расходы на сырье и мат.:",font=("times",10))

            MatEnt = Entry(frame1,width=12,font=("times",10))
            
            MatLab.place(relx=0.05,rely=0.08,anchor=W)

            MatEnt.place(relx=0.68,rely=0.08,anchor=W)

            frame1.place(relx=0.03,rely=0.519,anchor=W)
           
    Ch = Toplevel(root,bd=2)
    Ch.title("Расходы по статьям")
    Ch.transient(root)
    X_co1 = IntVar()
    Y_co1 = IntVar()
    X_co1.set((int(root.winfo_screenwidth())-400)/2)
    Y_co1.set((int(root.winfo_screenheight())-340)/2)
    Ch.geometry("400x340"+"+"+str(X_co1.get())+"+"+str(Y_co1.get()))
    Ch.resizable(height=0,width=0)

    Chooose = Label(Ch,text="Выберите статью расходов:")

    Types = Listbox(Ch,height=10,width=20,font=("times",10))
    Charges=[u'Оплата труда',u'Амортизация',
             u'Электроэнергия',u'Аренда',
             u'Налог на имущество','Прочие расходы',
             u'Сырье и материалы']
    for i in Charges:
        Types.insert(END,i)
    Types.bind("<Double-Button-1>",Show_charges)
    Addtype = Button(Ch,text="Добавить",font=("times",10))
    Proceed = Button(Ch,text="  OK  ",font=("times",10))
    
    Chooose.place(relx=0.5,rely=0.05,anchor=N)
    Addtype.place(relx=0.78,rely=0.65,anchor=N)
    Proceed.place(relx=0.5,rely=0.89,anchor=N)
    Types.place(relx=0.78,rely=0.14,anchor=N)
    
root.title("Profit")
X_co=IntVar()
Y_co=IntVar()
X_co.set((int(root.winfo_screenwidth())-682)/2)
Y_co.set((int(root.winfo_screenheight())-512)/2)
root.geometry("682x512"+"+"+str(X_co.get())+"+"+str(Y_co.get()))
root.resizable(width=0,height=0)

photo = PhotoImage(file="BgImg.gif")
Background = Label(image=photo)
Background.image = photo
Background.place(x=0.1,y=0.1)

GainMainWithNLab = Label(root,text="Выручка осн. c НДС:",bg="white",font=('times',10))
GainMainWithNLab.bind("<Button-1>",Main_prof)
GainMainWithNVal = Label(root,textvariable=GainMainWithNVar,bg="white",font=("times",10))
GainPropWithNLab = Label(root,text="Выручка продажи им-ва с НДС:",bg="white",font=("times",10))
GainPropWithNLab.bind("<Button-1>",Prop_prof)
GainPropWithNVal = Label(root,textvariable=GainPropWithNVar,bg="white",font=("times",10))
GainOthLab = Label(root,text="Прочие доходы:",bg="white",font=("times",10))
GainOthLab.bind("<1>",OthAct)
GainOthVal = Label(root,textvariable=GainOthVar,bg="white",font=("times",10))

NDSMainLab = Label(root,text="НДС:",bg="white",font=("times",10))
NDSMainVal = Label(root,textvariable=NDSMainVar,bg="white",font=("times",10))
GainMainWONLab = Label(root,text="Выручка осн. без НДС",bg="white",font=("times",10))
GainMainWONVal = Label(root,textvariable=GainMainWONVar,bg="white",font=("times",10))
NDSPropLab = Label(root,text="НДС:",bg="white",font=("times",10))
NDSPropVal = Label(root,textvariable=NDSPropVar,bg="white",font=("times",10))
GainPropWONLab = Label(root,text="Выручка от им-ва без НДС:",bg="white",font=("times",10))
GainPropWONVal = Label(root,textvariable=GainPropWONVar,bg="white",font=("times",10))
OtherChargeLab = Label(root,text="Прочие расходы:",bg="white",font=("times",10))
OtherChargeVal = Label(root,textvariable=OtherChargeVar,bg="white",font=("times",10))

CurrChargeLab = Label(root,text="Текущие расходы:",bg="white",font=("times",10))
CurrChargeLab.bind("<Button-1>",Charge)
CurrChargeVal = Label(root,textvariable=CurrChargeVar,bg="white",font=("times",10))
ProfMainLab = Label(root,text="Прибыль осн.:",bg="white",font=("times",10))
ProfMainVal = Label(root,textvariable=ProfMainVar,bg="white",font=("times",10))
ResPrCostLab = Label(root,text="Ост. имущества:",bg="white",font=("times",10))
ResPrCostVal = Label(root,textvariable=ResPrCostVar,bg="white",font=("times",10))
ProfPropLab = Label(root,text="Прибыль от продажи им-ва:",bg="white",font=("times",10))
ProfPropVal = Label(root,textvariable=ProfPropVar,bg="white",font=("times",10))
OtherProfLab = Label(root,text="Прочая прибыль:",bg="white",font=("times",10))
OtherProfVal = Label(root,textvariable=OtherProfVar,bg="white",font=("times",10))

ProfBefTLab = Label(root,text="Прибыль до налогооблажения:",bg="white",font=("times",10))
ProfBefTVal = Label(root,textvariable=ProfBefTVar,bg="white",font=("times",10))

ProfTaxLab = Label(root,text="Налог на прибыль",bg="white",font=("times",10))
ProfTaxVal = Label(root,textvariable=ProfTaxVar,bg="white",font=("times",10))
PureProfLab = Label(root,text="Чистая прибыль",bg="white",font=("times",10))
PureProfVal = Label(root,textvariable=PureProfVar,bg="white",font=("times",10))

GainMainWithNLab.place(relx=0.167,rely=0.0416,anchor=N)
GainMainWithNVal.place(relx=0.167,rely=0.0833,anchor=N)
GainPropWithNLab.place(relx=0.5,rely=0.0416,anchor=N)
GainPropWithNVal.place(relx=0.5,rely=0.0833,anchor=N)
GainOthLab.place(relx=0.833,rely=0.0416,anchor=N)
GainOthVal.place(relx=0.833,rely=0.0833,anchor=N)

NDSMainLab.place(relx=0.0833,rely=0.208,anchor=N)
NDSMainVal.place(relx=0.0833,rely=0.25,anchor=N)
GainMainWONLab.place(relx=0.25,rely=0.208,anchor=N)
GainMainWONVal.place(relx=0.25,rely=0.25,anchor=N)
NDSPropLab.place(relx=0.417,rely=0.208,anchor=N)
NDSPropVal.place(relx=0.417,rely=0.25,anchor=N)
GainPropWONLab.place(relx=0.583,rely=0.208,anchor=N)
GainPropWONVal.place(relx=0.583,rely=0.25,anchor=N)
OtherChargeLab.place(relx=0.8,rely=0.208,anchor=N)
OtherChargeVal.place(relx=0.8,rely=0.25,anchor=N)

CurrChargeLab.place(relx=0.1,rely=0.375,anchor=N)
CurrChargeVal.place(relx=0.1,rely=0.417,anchor=N)
ProfMainLab.place(relx=0.27,rely=0.375,anchor=N)
ProfMainVal.place(relx=0.27,rely=0.417,anchor=N)
ResPrCostLab.place(relx=0.43,rely=0.375,anchor=N)
ResPrCostVal.place(relx=0.43,rely=0.417,anchor=N)
ProfPropLab.place(relx=0.65,rely=0.375,anchor=N)
ProfPropVal.place(relx=0.65,rely=0.417,anchor=N)
OtherProfLab.place(relx=0.917,rely=0.375,anchor=N)
OtherProfVal.place(relx=0.917,rely=0.417,anchor=N)

ProfBefTLab.place(relx=0.5,rely=0.541,anchor=N)
ProfBefTVal.place(relx=0.5,rely=0.583,anchor=N)

ProfTaxLab.place(relx=0.33,rely=0.708,anchor=N)
ProfTaxVal.place(relx=0.33,rely=0.75,anchor=N)
PureProfLab.place(relx=0.66,rely=0.708,anchor=N)
PureProfVal.place(relx=0.66,rely=0.75,anchor=N)

root.mainloop()

